Address heatmap

We create a heatmap of all the addresses in Belgium, where brighter areas mean a higher density of addresses.

In [1]:
import datashader as ds
import pandas as pd
from colorcet import fire
from datashader import transfer_functions as tf

Reading the csv file into memory, this assumes you have the file of all addresses in Belgium saved in the following folder

In [2]:
# read the csv file
df = pd.read_csv('../data/belgium_addresses.csv')

Address heatmap

Using the datashader library we can create fast visualizations of very big datasets. We create a heatmap of the addresses in Belgium, where each address is plotted on the image, the pixels are then colored according to the density of addresses contained in the pixel.

In [3]:
x_name = 'EPSG:31370_x'
y_name = 'EPSG:31370_y'

plot_width  = 1024
# set data aspect ratio to be 1:1 
x_range = df[x_name].max() - df[x_name].min()
y_range = df[y_name].max() - df[y_name].min()
factor = y_range / x_range
plot_height = int(factor * plot_width)
# plot the data
agg = ds.Canvas(plot_width, plot_height).points(df, x_name, y_name)
tf.set_background(tf.dynspread(tf.shade(agg, cmap=fire)),"black")
Out[3]:
In [ ]: